package Model;
import java.util.*;

public class AddTaskCommand implements Command
{
	//attributes
	private Task newtask;
	private ArrayList<Task> TasksPointer;
	private boolean undo;
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	public AddTaskCommand(ArrayList<Task> PointerToTasks)
	{
		TasksPointer=PointerToTasks;
        undo = false;
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	public void execute(String taskName, Date taskDate, String iPeriodic, String PeriodicFrequency)  //periodicFrequency should be either Daily, Weekly or Monthly or null
	{                                                                                                 //"Single", "Periodic" or "Complex" as parameters of iPeriodic

         if(iPeriodic.equals("Single"))
         {
            newtask = new SingleTask(taskName,taskDate,iPeriodic);
            TasksPointer.add(newtask);
         }

         else if(iPeriodic.equals("Periodic"))
         {
            newtask = new PeriodicTask(taskName,taskDate,iPeriodic,PeriodicFrequency);
            TasksPointer.add(newtask);
         }

         else if(iPeriodic.equals("Complex"))
         {
            newtask = new ComplexTask(taskName,taskDate,iPeriodic);
            TasksPointer.add(newtask);
         }

	}

    //-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	//implmentation due to interface
	public void undo()
	{
		if(newtask != null && undo==false)
		{
			TasksPointer.remove(newtask);
            undo=true;
		}//end of outer-if
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	public void redo()
	{
		if(newtask != null && undo)
		{
			TasksPointer.add(newtask);
            undo=false;
		}
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
}

